/**
 *
 */
package 场景.瞬间高并发请求.redis;

import java.util.concurrent.atomic.LongAdder;

/**
 * @Title:
 * @author zhoujie
 * @date 2019年1月12日 下午2:01:22
 *
 */
public class InvDao {
    private Integer inv = 100;
    private LongAdder count = new LongAdder();

    public InvDao() {
    }

    public InvDao(Integer inv) {
        super();
        this.inv = inv;
    }

    /**
     * 模拟读库存
     *
     * @return the inv
     */
    public Integer getInv() {
        return inv;
    }

    /**
     * 模拟更新数据库
     *
     * @param number
     *            购买数量
     * @return 0：更新成功 1：更新失败
     */
    public Integer outInv(Integer number) {
        count.add(1);
        if (inv >= number) {
            inv -= number;
            return 1;
        }
        return 0;
    }

    /**
     * @return the count
     */
    public LongAdder getCount() {
        return count;
    }

    /**
     * @param count the count to set
     */
    public void setCount(LongAdder count) {
        this.count = count;
    }

}
